package com.example.mall.web.controller;

import com.example.mall.domain.LogisticsCompanies;
import com.example.mall.dto.LogisticsCompaniesDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.LogisticsCompaniesQuery;
import com.example.mall.query.PageDTO;
import com.example.mall.result.JSONResult;
import com.example.mall.service.ILogisticsCompaniesService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/logisticsCompanies")
public class LogisticsCompaniesController {

    @Autowired
    public ILogisticsCompaniesService logisticsCompaniesService;

    /**
     * 分页查询物流公司表信息
     * @param logisticsCompaniesQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询物流公司表信息",notes = "分页查询物流公司表信息",httpMethod = "GET")
    public JSONResult queryPage(LogisticsCompaniesQuery logisticsCompaniesQuery){
        PageDTO<LogisticsCompaniesDto> logisticsCompaniesDtoPageDTO = logisticsCompaniesService.queryPage(logisticsCompaniesQuery);
        return JSONResult.success("查询成功",logisticsCompaniesDtoPageDTO);
    }

    /**
     * 根据id查询物流公司表信息
     * @param campanyId
     * @return
     */
    @GetMapping("query/{campanyId}")
    @ApiOperation(value = "根据id查询物流公司表信息",notes = "根据id查询物流公司表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("campanyId")Long campanyId){
        //1.根据id查询用户信息
        if (campanyId == null){
            throw new GlobalCustomerException(ErrorEnumCode.CAMPANYID_NOT_ID);
        }
        LogisticsCompanies logisticsCompanies = logisticsCompaniesService.getById(campanyId);
        return JSONResult.success("查询成功",logisticsCompanies);
    }

    /**
     * 根据id查询物流公司表信息
     * @param campanyId
     * @return
     */
    @GetMapping("queryLogisticsCompaniesById/{campanyId}")
    @ApiOperation(value = "根据id查询物流公司表信息",notes = "根据id查询物流公司表信息",httpMethod = "GET")
    public JSONResult queryLogisticsCompaniesById(@PathVariable("campanyId")Long campanyId){
        //1.根据id查询用户信息
        if (campanyId == null){
            throw new GlobalCustomerException(ErrorEnumCode.CAMPANYID_NOT_ID);
        }
        LogisticsCompanies logisticsCompanies = logisticsCompaniesService.queryLogisticsCompaniesById(campanyId);
        return JSONResult.success("查询成功",logisticsCompanies);
    }

    /**
     * 查询全部物流公司表信息
     * @param
     * @return
     */
    @GetMapping("queryLogisticsCompaniesList")
    @ApiOperation(value = "查询全部物流公司表信息",notes = "查询全部物流公司表信息",httpMethod = "GET")
    public JSONResult queryLogisticsCompaniesList(){
        List<LogisticsCompanies> logins = logisticsCompaniesService.queryLogisticsCompaniesList();
        return JSONResult.success("查询成功",logins);
    }

    /**
     * 新增物流公司表
     * @param logisticsCompaniesDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增物流公司表",notes = "新增物流公司表",httpMethod = "POST")
    public JSONResult insert(@RequestBody LogisticsCompaniesDto logisticsCompaniesDto){
        logisticsCompaniesService.insert(logisticsCompaniesDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改物流公司表信息
     * @param logisticsCompaniesDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改物流公司表信息",notes = "修改物流公司表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody LogisticsCompaniesDto logisticsCompaniesDto){
        logisticsCompaniesService.update(logisticsCompaniesDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除物流公司表信息
     * @param campanyId
     * @return
     */
    @PostMapping("delete/{campanyId}")
    @ApiOperation(value = "删除物流公司表信息",notes = "删除物流公司表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("campanyId") Long campanyId) {
        logisticsCompaniesService.delete(campanyId);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除物流公司表信息
     * @param campanyIds
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除物流公司表信息",notes = "批量删除物流公司表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> campanyIds) {
        logisticsCompaniesService.deleteBatch(campanyIds);
        return JSONResult.success("批量删除成功");
    }
}
